/**
 * form表正则判定
 */
var reserve = '';
function checkname() {
	var idcard = document.getElementById("IDcard").value; //获取证件号
	var regId = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;

	var phone = document.getElementById("PhoneNumber").value; //获取手机号码
	var regphone = /^[1][3,4,5,7,8][0-9]{9}$/;
	var cname2 = document.getElementById("firstname").value; //获取中文姓1
	var cname1 = document.getElementById("cname1").value; //获取中文名1
	
	var regFirstName = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{1,2}$/;// 姓
	var regName = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{1,20}$/;// 名
	
	
	if(number==2){
		var cname3 = document.getElementById("cname3").value; //获取中文名2
		var cname4 = document.getElementById("firstname2").value; //获取中文姓2
		var idcard2 = document.getElementById("IDcard2").value; //获取证件号
		var phone2 = document.getElementById("Phone2").value; //获取手机号
	}

	var ContactName = document.getElementById("ContactName").value; //获取联系人名字
	var phone3 = document.getElementById("Phone3").value; //获取手机号
	var email = document.getElementById("Email").value; //获取邮箱内容
	var regmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;

	var weixing = document.getElementById("WeiXing").value;
	var regweixing = /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/;

	if(!regName.test(cname1)) {
		var label = '';
		label += ' <label style="color: red"  >请输入中文名</label>';
		document.getElementById("nameth").innerHTML = label;
	}
	if(!regFirstName.test(cname2)) {
		var label = '';
		label += ' <label style="color: red"  >请输入中文性</label>';
		document.getElementById("firstnamelable").innerHTML = label;

	}

	if(!regId.test(idcard)) {
		var label = '';
		label += ' <label style="color: red"  >请输入正确的证件号</label>';
		document.getElementById("IDcarLable").innerHTML = label;
	}

	if(!regphone.test(phone)) {
		var label = '';
		label += ' <label style="color: red"  >请输入正确的手机号</label>';
		document.getElementById("Phonelabel").innerHTML = label;
	}

	

	
	if(number==2){
		if(!regName.test(cname3)) {
			var label = '';
			label += ' <label style="color: red"  >请输入中文名</label>';
			document.getElementById("cnamelable3").innerHTML = label;
	
		}
	
		if(!regFirstName.test(cname4)) {
			var label = '';
			label += ' <label style="color: red"  >请输入中文性</label>';
			document.getElementById("firstnamelable2").innerHTML = label;
	
		}
	
		if(!regId.test(idcard2)) {
			var label = '';
			label += ' <label style="color: red"  >请输入正确的证件号</label>';
			document.getElementById("IDcardLable2").innerHTML = label;
		}
	
		if(!regphone.test(phone2)) {
			var label = '';
			label += ' <label style="color: red"  >请输入正确的手机号</label>';
			document.getElementById("PhoneLable2").innerHTML = label;
		}
	}
	
	

	if(!regName.test(ContactName)) {
		var label = '';
		label += ' <label style="color: red"  >请输入正确联系人姓名</label>';
		document.getElementById("ContactNameLable").innerHTML = label;

	}

	if(!regphone.test(phone3)) {
		var label = '';
		label += ' <label style="color: red"  >请输入正确的手机号</label>';
		document.getElementById("PhoneLable3").innerHTML = label;
	}

	if(!regmail.test(email)) {
		var label = '';
		label += ' <label style="color: red"  >邮箱格式错误</label>';
		document.getElementById("EmailLable").innerHTML = label;

	}

	if(!regweixing.test(weixing)) {
		var label = '';
		label += ' <label style="color: red"  >微信格式错误</label>';
		document.getElementById("WeiXingLable").innerHTML = label;
	}

}

function ReturnName() {

	document.getElementById("nameth").innerHTML = " 中文名 ";
	document.getElementById("IDcarLable").innerHTML = " 证件号 ";
	document.getElementById("Phonelabel").innerHTML = " 手机号 ";
	document.getElementById("firstnamelable").innerHTML = " 中文姓 ";
	
	if(number == 2){
		document.getElementById("firstnamelable2").innerHTML = " 中文姓 ";
		document.getElementById("cnamelable3").innerHTML = " 中文名 ";
		document.getElementById("IDcardLable2").innerHTML = " 证件号 ";
		document.getElementById("PhoneLable2").innerHTML = " 手机号 ";
	}
	
	document.getElementById("ContactNameLable").innerHTML = "联系人姓名";
	document.getElementById("PhoneLable3").innerHTML = " 手机号 ";
	document.getElementById("EmailLable").innerHTML = " 邮箱 ";
	document.getElementById("WeiXingLable").innerHTML = " 微信 ";

}

function checkAll() {

	var idcard = document.getElementById("IDcard").value; //获取证件号
	var regId = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	var phone = document.getElementById("PhoneNumber").value; //获取手机号码
	var regphone = /^[1][3,4,5,7,8][0-9]{9}$/;

	var cname1 = document.getElementById("cname1").value; //获取中文名
	var cname2 = document.getElementById("firstname").value; //获取中文姓
	var regFirstName = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{1,2}$/;
	
	var regName = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{1,20}$/;
	
	var ContactName = document.getElementById("ContactName").value; //获取联系人名字

	var phone3 = document.getElementById("Phone3").value; //获取手机号
	var email = document.getElementById("Email").value; //获取邮箱内容
	var regmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;

	var weixing = document.getElementById("WeiXing").value;
	var regweixing = /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/;

	reserve = document.getElementsByName("reserve");
	
	if(number==2){
		var cname3 = document.getElementById("cname3").value; //获取中文名
		var cname4 = document.getElementById("firstname2").value; //获取中文姓
	
		var idcard2 = document.getElementById("IDcard2").value; //获取证件号
		var phone2 = document.getElementById("Phone2").value; //获取手机号
		
		// 出生日期-1
		var birthDay1 = year1+"-"+month1+"-"+day1; // 2020-08-01
		
		// 出生日期-2
		var birthDay2 = year2+"-"+month2+"-"+day2; // 2020-08-01
		
		var gender1=$("input[name='sex1']:checked").val();
		
		

		var hotel_id = getUrlParam("hotel_id");
		var startDate = getUrlParam("startDate");
		var endDate = getUrlParam("endDate");
		var sumPrice = getUrlParam("sumPrice");
		
		
		if(reserve[0].checked && regName.test(cname1)&&regName.test(cname3) && regFirstName.test(cname4) 
		&& regId.test(idcard2) && regphone.test(phone2)&& regId.test(idcard) && regphone.test(phone)
		&& regFirstName.test(cname2) && regName.test(ContactName) && regphone.test(phone3) 
		&& regmail.test(email) && regweixing.test(weixing)) {
			
			// 姓-1
			$("#first_name1").val(cname2);
			// 名-1
			$("#last_name1").val(cname1);
			
			// 男女-1
			var gender1=$("input[name='sex1']:checked").val();
			$("#select_Sex1").val(gender1);
			
			// 出生日期-1
			var birthDay1 = year1+"-"+month1+"-"+day1; // 2020-08-01
			$("#select_Birthday1").val(birthDay1);
			
			/*获取证件类型-1*/
			var value1 = $("#IDtype1").val();
			var IDtype1= $("#IDtype1").find("option[value="+ value1 +"]").text();
			$("#select_IDtype1").val(IDtype1);
			
			// 证件号码-1
			$("#idcard_1").val(idcard);
			// 手机号码-1
			$("#phone_1").val(phone);
			
			
			// 姓-2
			$("#first_name2").val(cname4);
			// 名-2
			$("#last_name2").val(cname3);
			// 男女-2
			var gender2=$("input[name='sex2']:checked").val();
			$("#select_Sex2").val(gender2);
			// 出生日期-2
			var birthDay2 = year2+"-"+month2+"-"+day2; // 2020-08-01
			$("#select_Birthday2").val(birthDay2);
			
			/*获取证件类型-2*/
			var value2 = $("#IDtype2").val();
			var IDtype2= $("#IDtype2").find("option[value="+ value2 +"]").text();
			$("#select_IDtype1").val(IDtype2);
			console.log("IDtype2="+IDtype2);
			
			// 证件号码-2
			$("#idcard_2").val(idcard2);
			// 手机号码-2
			$("#phone_2").val(phone2);
			
			/*联系人篇*/
			$("#Contact_Name").val(ContactName);
			$("#phone_3").val(phone3);
			$("#Email").val(email);
			$("#wei_xing").val(weixing);
			
			$.ajax({
				url: "/JavaWeb项目_第六组/inform?method=querys",
				type: 'get',
				asasync:true,
				data:{
					number:number,
					hotel_id:hotel_id,
					startDate:startDate,
					endDate:endDate,
					sumPrice:sumPrice,
					
					cname2:cname2,
					cname1:cname1,
					gender1:gender1,
					birthDay1:birthDay1,
					IDtype1:IDtype1,
					idcard1:idcard,
					phone1:phone,
					
					cname4:cname4,
					cname3:cname3,
					gender2:gender2,
					birthDay2:birthDay2,
					IDtype2:IDtype2,
					idcard2:idcard2,
					phone2:phone2,
					
					ContactName:ContactName,
					phone3:phone3,
					email:email,
					weixing:weixing,
					
				},
				dataType: "json",
				success: function (data) {
					alert(data.price);
					// 去支付Ajax
					goToPay(data.price,data.pay_number,user_id);
				}
			});
			
			return true;
		} else {
			alert("请将信息填写完整并同意电子合同");
			return false;
		}
	}else{
		var hotel_id = getUrlParam("hotel_id");
		console.log("酒店的id-->"+hotel_id);
		var startDate = getUrlParam("startDate");
		var endDate = getUrlParam("endDate");
		var sumPrice = getUrlParam("sumPrice");
		console.log("startDate="+startDate);
		console.log("endDate="+endDate);
		console.log("sumPrice="+sumPrice);
		
		if(reserve[0].checked && regName.test(cname1) && regId.test(idcard) && regphone.test(phone)&& regFirstName.test(cname2) && regName.test(ContactName) && regphone.test(phone3) && regmail.test(email) && regweixing.test(weixing)) {
			// 姓-1
			$("#first_name1").val(cname2);
			// 名-1
			$("#last_name1").val(cname1);
			// 男女-1
			var gender=$("input[name='sex1']:checked").val();
			$("#select_Sex1").val(gender);
			// 出生日期-1
			var birthDay1 = year1+"-"+month1+"-"+day1; // 2020-08-01
			$("#select_Birthday1").val(birthDay1);
			
			/*获取证件类型-1*/
			var value = $("#IDtype1").val();
			var IDtype= $("#IDtype1").find("option[value="+ value +"]").text();
			$("#select_IDtype1").val(IDtype);
			
			// 证件号码-1
			$("#idcard_1").val(idcard);
			// 手机号码-1
			$("#phone_1").val(phone);
			
			
			/*联系人篇*/
			$("#Contact_Name").val(ContactName);
			$("#phone_3").val(phone3);
			$("#Email").val(email);
			$("#wei_xing").val(weixing);
			
			console.log("=======inform？querys方法运行==========")
			$.ajax({
				url: "/JavaWeb项目_第六组/inform?method=querys",
				type: 'get',
				asasync:true,
				data:{
					number:number,
					hotel_id:hotel_id,
					startDate:startDate,
					endDate:endDate,
					sumPrice:sumPrice,
					
					cname2:cname2,
					cname1:cname1,
					gender1:gender,
					birthDay1:birthDay1,
					IDtype1:IDtype,
					idcard1:idcard,
					phone1:phone,
					
					ContactName:ContactName,
					phone3:phone3,
					email:email,
					weixing:weixing,
					
				},
				dataType: "json",
				success: function (data) {
					console.log("pay_number--->"+data.price);
					console.log("pay_number--->"+data.pay_number);
					// 去支付的Ajax
					goToPay(data.price,data.pay_number,user_id);
				}
			});
			
			
			return true;
		} else {
			alert("请将信息填写完整并同意电子合同");
			return false;
		}
	}

	
}


function goToPay (price,pay_number,user_id) {
	$.ajax({
		url:"/JavaWeb项目_第六组/post?method=showPayment",
		type: 'get',
		asasync:true,
		data:{
			id:price,
			pay_number:pay_number,
			zc_user_id:user_id,
		},
		dataType: "json",
		success: function (data) {
			console.log("成功...")
			window.location.href= "../dhy/payment.jsp";
		}
	});
}



